home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak Vol A-4
/
(Vol A-4) Vol. A4.iso
/
Games
/
smashing.swf
/
scripts
/
frame_31
/
DoAction.as
Wrap
Text File
|
2008-03-12
|
11KB
|
295 lines
function hitBrick(ball)
{
ball.pixelsMoveX = (ball.testMoveX - ball.testMoveXTemp) / iterations;
ball.pixelsMoveY = (ball.testMoveY - ball.testMoveYTemp) / iterations;
b = 1;
while(iterations >= b)
{
ball.testMoveX = ball.testMoveXTemp + ball.pixelsMoveX * b;
ball.testMoveY = ball.testMoveYTemp + ball.pixelsMoveY * b;
if(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
{
i = 1;
while(brickNumber >= i)
{
if(bricks["brick" + i].hitTest(ball.testMoveX,ball.testMoveY,true) && !bricks["brick" + i].brickSmashed)
{
activeBrick = bricks["brick" + i];
break;
}
i++;
}
break;
}
b++;
}
if(!activeBrick.invisible)
{
brickEdgeLeft = activeBrick._x - activeBrick._width / 2;
brickEdgeTop = activeBrick._y - activeBrick._height / 2;
brickEdgeBottom = activeBrick._y + activeBrick._height / 2;
brickEdgeRight = activeBrick._x + activeBrick._width / 2;
distanceToTopEdge = makePositive(ball.testMoveY - brickEdgeTop,true);
distanceToLeftEdge = makePositive(ball.testMoveX - brickEdgeLeft,true);
distanceToBottomEdge = makePositive(ball.testMoveY - brickEdgeBottom,true);
distanceToRightEdge = makePositive(ball.testMoveX - brickEdgeRight,true);
timeSinceLastBounce = getTimer() - ballLastBounced;
timeSinceLastBounce = 200;
if(!activeBrick.destructible && ball.powerBall or !ball.powerBall)
{
if(ball.SpeedX < 0 && ball.SpeedY < 0)
{
if(distanceToTopEdge < distanceToLeftEdge)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(ball.SpeedX < 0 && 0 < ball.SpeedY)
{
if(distanceToBottomEdge < distanceToLeftEdge)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(0 < ball.SpeedX && ball.SpeedY < 0)
{
if(distanceToTopEdge < distanceToRightEdge)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(0 < ball.SpeedX && 0 < ball.SpeedY)
{
if(distanceToBottomEdge < distanceToRightEdge)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "left";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
}
else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
{
if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
{
hitEdge = "bottom";
ballBounce(ball,activeBrick,hitEdge);
}
else
{
hitEdge = "top";
ballBounce(ball,activeBrick,hitEdge);
}
}
else
{
hitEdge = "right";
ballBounce(ball,activeBrick,hitEdge);
}
}
}
}
if((activeBrick.destructible or activeBrick.destructible == hitEdge) && !activeBrick.brickSmashed)
{
activeBrick.brickSmashed = true;
removeBrick(activeBrick,ball);
if(activeBrick.brickType != "bonus")
{
sndPop.start();
}
}
else if(activeBrick.multihit && !activeBrick.brickSmashed)
{
activeBrick.play();
sndIndestructibleHit.start();
}
else if(!activeBrick.invisible)
{
sndIndestructibleHit.start();
}
ball.randomizeMovementCounter = ball.randomizeMovementCounter + 1;
ball.randomSpeed = (Math.random() - 0.5) / 10;
ball.SpeedY += ball.randomSpeed;
ball.SpeedX += ball.randomSpeed;
}
function removeBrick(activeBrick, ball)
{
if(!gameOver)
{
activeBrick.gotoAndPlay("remove");
activeBrick.ball = ball;
smashedBricks++;
bricksLeft = totalBricks - smashedBricks;
if(!activeBrick.expired)
{
addPoints(activeBrick,activeBrick.pointsWorth);
}
if(activeBrick.brickType != "bonus" && !ball.powerBall && !activeBrick.blownAway)
{
bonusActions();
}
if(bricksLeft < 1)
{
sndLevelCompleted.start();
clipCounter++;
attachMovie("mcPleaseWait","mcPleaseWait" + clipCounter,clipCounter);
this["mcPleaseWait" + clipCounter]._x = 320;
this["mcPleaseWait" + clipCounter]._y = 240;
bricks.play();
}
menu.txtBricksLeft = bricksLeft;
}
}
function brickMove(brickMovieClip, jumpsLeft, jumpsRight)
{
if(!gamePaused)
{
if(getTimer() >= brickMovieClip.movingBrickPause)
{
if(0 < brickMovieClip.jumpsLeft && brickMovieClip.jumpsLeftCounter < brickMovieClip.jumpsLeft)
{
brickMovieClip._x -= 30;
brickMovieClip.jumpsLeftCounter = brickMovieClip.jumpsLeftCounter + 1;
}
else if(0 < brickMovieClip.jumpsRight && brickMovieClip.jumpsRightCounter < brickMovieClip.jumpsRight)
{
brickMovieClip._x += 30;
brickMovieClip.jumpsRightCounter = brickMovieClip.jumpsRightCounter + 1;
}
else
{
if(!brickMovieClip.moveBrickInit)
{
brickMovieClip.jumpsLeft += brickMovieClip.jumpsRightOrig - 1;
brickMovieClip.moveBrickInit = true;
}
brickMovieClip.jumpsLeftCounter = 0;
brickMovieClip.jumpsRightCounter = 0;
brickMovieClip._x -= 30;
}
brickMovieClip.movingBrickPause = movingBrickPauseOrig + getTimer();
}
}
}
multiHitPause = 2000;
movingBrickPauseOrig = 1000;
gotoAndPlay(40);